import { notification as Notification } from 'ant-design-vue';
import * as CommonUtils  from '../../utils/util.js';

class Notice {
  /**
   * 成功提示
   * @param options
   */
  success(options) {
    this.checkArgs('success', options);
  }

  /**
   * 成功提示
   * @param title
   * @param desc
   * @param options
   */
  success(title, desc, options) {
    this.checkArgs('success', title, desc, options);
  }

  /**
   * 警告提示
   * @param options
   */
  warning(options) {
    this.checkArgs('warning', options);
  }

  /**
   * 警告提示
   * @param title
   * @param desc
   * @param options
   */
  warning(title, desc, options) {
    this.checkArgs('warning', title, desc, options);
  }

  /**
   * 错误提示
   * @param options
   */
  error(options) {
    this.checkArgs('error', options);
  }

  /**
   * 错误提示
   * @param title
   * @param desc
   * @param options
   */
  error(title, desc, options) {
    this.checkArgs('error', title, desc, options);
  }

  /**
   * 信息提示
   * @param options
   */
  info(options) {
    this.checkArgs('info', options);
  }

  /**
   * 信息提示
   * @param title
   * @param desc
   * @param options
   */
  info(title, desc, options) {
    this.checkArgs('info', title, desc, options);
  }

  /**
   * 入参检查
   * @param type
   * @param arg
   * @param desc
   * @param options
   */
  checkArgs(type, arg, desc, options) {
    if (typeof arg === 'object' && CommonUtils.isNotNull(arg)) {
      this.open(type, arg);
    } else if (arg && CommonUtils.isNull(desc)) {
      this.open(null, arg, type, options);
    } else {
      this.open(arg, desc, type, options);
    }
  }

  /**
   * 打开提醒框
   * @param type
   * @param options
   */
  open(type, options) {
    if (typeof type === 'string') {
      Notification[type]({
        message: '提示',
        description: '',
        duration: 3,
        ...(options || {}),
      });
    } else {
      Notification[type]({
        message: options.message || '提示',
        description: options.description,
        duration: 3,
        ...options,
      });
    }
  }
}

export const notice = new Notice();
